package com.juc.callable.callable8;

import java.beans.FeatureDescriptor;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 
 * 方法execute()与submit()
 * 方法execute没有返回值而 submit方法可以有返回值
 * 方法execute在默认情况下异常直接抛出，不能捕获，但是可以通过ThreadFacTory
 * 方式捕获，而submit默认情况下，可以catch ExecutionException捕获异常
 *
 */
public class Test1 {

	/**
	 * 有/无返回值的测试
	 */
	public static void main(String[] args) {
		try {
			ThreadPoolExecutor executor = new ThreadPoolExecutor(50, Integer.MAX_VALUE, 5, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>());
			executor.execute(new Runnable() {
				
				@Override
				public void run() {
					System.out.println("execute() 方法执行了，没有返回值！");
					
				}
			});
			Future<String> future = executor.submit(new Callable<String>() {
	
				@Override
				public String call() throws Exception {
					System.out.println("submit() 方法执行了， 有返回值！");
					return "我是返回值";
				}
			});
			System.out.println(future.get());
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
